package com.itheima.service.impl;

import com.itheima.entity.Dish;
import com.itheima.entity.Emp;
import com.itheima.entity.PageBean;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.DishMapper;
import com.itheima.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
public class DishServicelmpl implements DishService {
    @Autowired
    DishMapper dishMapper;

    @Override
    public void saveDept(Dish dish) {
        // 1. 补全基础属性：createTime  / updateTime
        dish.setCreateTime(LocalDateTime.now());
        dish.setUpdateTime(LocalDateTime.now());
        dish.setCategoryId(1);
        dishMapper.save(dish);
    }
//根据id查询菜品信息
    @Override
    public Emp queryOne(Integer id) {
        Emp emp =   dishMapper.queryOne(id);

        return emp;
    }
   // 更新
    @Override
    public void update(Dish dish) {
        dish.setCreateTime(LocalDateTime.now());
        dish.setUpdateTime(LocalDateTime.now());
        dishMapper.update(dish);
    }

    @Override
    public void delete(List<Integer> ids) {
        dishMapper.delete(ids);
    }

    /*
    * 起售，禁售
    * */
    @Override
    public void startOrStop(Integer status, Integer id) {
        //dish.setCreateTime(LocalDateTime.now());
        //dish.setUpdateTime(LocalDateTime.now());
        dishMapper.startOrStop(status,id);
    }
/*
* 分页查询菜品
*
* */
    @Override
    public PageBean pageQuery(Integer page, Integer pageSize) {
        Integer count = dishMapper.count();
        page = (page - 1) * pageSize;
        List<Class> studentList = dishMapper.pageQuery(page, pageSize);


        PageBean pageBean = new PageBean();
        pageBean.setTotal((count));
        pageBean.setRows(studentList);
        return pageBean;
    }
}
